//
//  NYAccountManager.m
//  Nooryes
//
//  Created by baken on 2020/2/28.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYAccountManager.h"
#import "NYAccountModel.h"
#import "NYArticleListModel.h"
#import "NYTopicListModel.h"
#import "NYMessageListModel.h"
#import "NYMainModel.h"

@implementation NYAccountManager


+(void)getUserInfoWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andCompletionHandle:(void (^)(NYAccountModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"id"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetUserInfomation]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYAccountModel *model = [NYAccountModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
    
}

+(void)getArticleCollectListWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andType:(NSString *)type andPage:(NSString *)page andCompletionHandle:(void (^)(NYArticleListModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [dict setValue:type forKey:@"type"];
    [dict setValue:page forKey:@"p"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetCollectList]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYArticleListModel *model = [NYArticleListModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
    
}


+(void)getTopicCollectListWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andType:(NSString *)type andPage:(NSString *)page andCompletionHandle:(void (^)(NYTopicListModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [dict setValue:type forKey:@"type"];
    [dict setValue:page forKey:@"p"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetCollectList]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYTopicListModel *model = [NYTopicListModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

+(void)getMessageListWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andPage:(NSString *)page andCompletionHandle:(void (^)(NYMessageListModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [dict setValue:page forKey:@"p"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetMsgList]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYMessageListModel *model = [NYMessageListModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

+(void)getMessageCountWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andCompletionHandle:(void (^)(NYMainModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetMsgCount]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYMainModel *model = [NYMainModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

@end
